// flatten函数
function wrap(){
  var ret=[];
  return function flat(a){
      for(var item of a){
          if(item.constructor===Array){
              ret.concat(flat(item))
          }else{
              ret.push(item)
          }
      }
      return ret
  }
}
const flatten1 = function (arr) {
  while (arr.some(item => Array.isArray(item))) {
    arr = [].concat(...arr)
  }
  return arr
}
// es6写法
const flatten2 = array => array.reduce((acc, cur) => (Array.isArray(cur) ? [...acc, ...flatten2(cur)] : [...acc, cur]), [])

//实现一个sleep函数
//Promise
const sleep = time => {
  return new Promise(resolve => setTimeout(resolve,time))
}
sleep(1000).then(()=>{
  console.log(1)
})

//Generator
function* sleepGenerator(time) {
  yield new Promise(function(resolve,reject){
    setTimeout(resolve,time);
  })
}
sleepGenerator(1000).next().value.then(()=>{console.log(1)})

//async
function sleep(time) {
  return new Promise(resolve => setTimeout(resolve,time))
}
async function output() {
  let out = await sleep(1000);
  console.log(1);
  return out;
}
output();

//ES5
function sleep(callback,time) {
  if(typeof callback === 'function')
    setTimeout(callback,time)
}

function output(){
  console.log(1);
}
sleep(output,1000);